package com.ruoyi.web.controller.gatewayadmin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gatewayadmin.domain.GatewayApp;
import com.ruoyi.gatewayadmin.service.IGatewayAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应用管理Controller
 *
 * @author Darwin
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/gatewayadmin/app")
public class GatewayAppController extends BaseController
{
    @Autowired
    private IGatewayAppService gatewayAppService;

    /**
     * 查询应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(GatewayApp gatewayApp)
    {
        startPage();
        List<GatewayApp> list = gatewayAppService.selectGatewayAppList(gatewayApp);
        return getDataTable(list);
    }

    /**
     * 导出应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:export')")
    @Log(title = "应用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GatewayApp gatewayApp)
    {
        List<GatewayApp> list = gatewayAppService.selectGatewayAppList(gatewayApp);
        ExcelUtil<GatewayApp> util = new ExcelUtil<GatewayApp>(GatewayApp.class);
        util.exportExcel(response, list, "应用管理数据");
    }

    /**
     * 获取应用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:query')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") String uuid)
    {
        return success(gatewayAppService.selectGatewayAppByUuid(uuid));
    }

    /**
     * 新增应用管理
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:add')")
    @Log(title = "应用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GatewayApp gatewayApp)
    {
        return toAjax(gatewayAppService.insertGatewayApp(gatewayApp));
    }

    /**
     * 修改应用管理
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:edit')")
    @Log(title = "应用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GatewayApp gatewayApp)
    {
        return toAjax(gatewayAppService.updateGatewayApp(gatewayApp));
    }

    /**
     * 删除应用管理
     */
    @PreAuthorize("@ss.hasPermi('gatewayadmin:app:remove')")
    @Log(title = "应用管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable String[] uuids)
    {
        return toAjax(gatewayAppService.deleteGatewayAppByUuids(uuids));
    }
}
